//transmit support for Matrix2D
//$Id: transmit_matrix2d.h 452 2010-04-11 17:34:31Z Oleg.Bulychov $
#pragma once

#include "src/heo/include/matrix2d.h"
#include "src/heo/include/transmit.h"
//__________________________________________________________________________________
//__________________________________________________________________________________
template<class X, class V>
struct transmit_handler<Matrix2D<X>, V>
{
    static void visit(Matrix2D<X>& m, V& v)
    {
        visit(m, v, meta::int2type<V::transmit_tag>());
    }

    static void visit(Matrix2D<X>& m, V& bcast, meta::int2type<BCAST_TAG>)
    {
        if (bcast.is_Root())
        {
            visit(m, bcast, meta::int2type<SEND_TAG>());
        }
        else
        {
            visit(m, bcast, meta::int2type<RECV_TAG>());
        }
    }

    static void visit(Matrix2D<X>& m, V& send, meta::int2type<SEND_TAG>)
    {
        size_t rows = m.get_Rows();
        size_t columns = m.get_Columns();
        send << rows << columns;
        size_t dim = rows * columns;
        if (dim > 0)
            send.visit_Array(&m[0][0], dim, "", 0);
    }

    static void visit(Matrix2D<X>& m, V& recv, meta::int2type<RECV_TAG>)
    {
        size_t rows = 0, columns = 0;
        recv >> rows >> columns;
        m.set_Resolution(rows, columns);
        size_t dim = rows * columns;
        if (dim > 0)
            recv.visit_Array(&m[0][0], dim, "", 0);
    }
};
//__________________________________________________________________________________
//__________________________________________________________________________________

//EOF!
